﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using System.IO.Pipes;

namespace LulzSea
{
    
    static class Program
    {
        static Mutex mutex = new Mutex(true, "_Mutex_djmati11ego_nie_tykac_LulzSea");
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            if (mutex.WaitOne(TimeSpan.Zero, true))
            {

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                using (Console new_console = new Console())
                {
                    new_console.args2 = args;
                    Application.Run(new_console);
                    mutex.ReleaseMutex();
                }
                
                
               
            }
            else
            {
                //Tutaj wysylanie wiadomosci
                using (NamedPipeClientStream pipeStream = new NamedPipeClientStream("_djmati11s_pipe_dont_touch_LulzSea"))
                {
                    pipeStream.Connect();
                    using (StreamWriter sw = new StreamWriter(pipeStream))
                    {
                        sw.AutoFlush = true;
                        foreach (string a in args)
                        {
                            sw.Write(a);
                        }
                    }
                    
                }
                Application.Exit();
            }

        }
    }
}
